/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rdb.sbean;

import com.rdb.entities.StudentExams;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TemporalType;

/**
 *
 * @author Bich Tran Van
 */
@Stateless
public class StudentExamsFacade extends AbstractFacade<StudentExams> {
    @PersistenceContext(unitName = "ResultDeclarationBoard-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public StudentExamsFacade() {
        super(StudentExams.class);
    }
    
    public List<StudentExams> getSchedule(String enRoll){
//        String query = "SELECT s FROM StudentExams WHERE s.studentId.enRoll  = :enRoll and s.examId.dateStart >= :dateStart order by s.examId.dateStart";
        String query = "SELECT s FROM StudentExams s WHERE s.studentId.enRoll  = :enRoll and s.examId.dateStart >= :dateStart order by s.examId.dateStart";
        javax.persistence.Query q = getEntityManager().createQuery(query);
        q.setParameter("enRoll", enRoll);
        Date dt = new Date();
        dt.setHours(0);
        dt.setMinutes(0);
        dt.setSeconds(0);
        q.setParameter("dateStart",dt, TemporalType.DATE);
        if(q.getResultList().isEmpty()){
            return null;
        }
        return q.getResultList();
    }
    
    public List<StudentExams> getMarks(String enRoll){
        String query = "SELECT s FROM StudentExams s WHERE s.studentId.enRoll  = :enRoll and s.examId.dateEnd <= :dateStart order by s.examId.dateStart";
        javax.persistence.Query q = getEntityManager().createQuery(query);
        q.setParameter("enRoll", enRoll);
        Date dt = new Date();
        dt.setHours(0);
        dt.setMinutes(0);
        dt.setSeconds(0);
        q.setParameter("dateStart",dt, TemporalType.DATE);
        if(q.getResultList().isEmpty()){
            return null;
        }
        return q.getResultList();
    }
    
}
